from faker import Faker
from models.models import User
from flask import Flask
from models.models import db

app = Flask(__name__)
app.config["SQLALCHEMY_DATABASE_URI"] = "mysql+pymysql://root:123456@localhost:3306/e-web"
db.init_app(app)

fake = Faker(locale='zh_CN')

with app.app_context():
    for i in range(100):
        profile = fake.simple_profile()
        existing_user = User.query.filter_by(username=profile['username']).first()
        if existing_user is None:
            _type = User(
                username=profile['username'],
                password="123",
                sex=profile['sex'],
                address=profile['address'],
                email=fake.email()  # Use fake.email() to generate a random email address
            )
            db.session.add(_type)
    db.session.commit()
